package com.db.javaschool.kislros;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

public class V2Tracker implements Tracker {
	private class ImmutablePoint extends Point {
		public ImmutablePoint(Point p) {
			super(p);
		}
	
		@Override
		public void apply(Point p) {
			throw new UnsupportedOperationException();
		}
	}
	
	private Map<String, ImmutablePoint> locs;
	
	public V2Tracker(Map<String, ImmutablePoint> m) {
		locs = new ConcurrentHashMap<>(m);
	}
	
	@Override
	public Point getLoc(String id) {
		return locs.get(id);
	}
	
	@Override
	public void setLoc(String id, Point p) {
		locs.get(id).apply(p);
	}
	
	@Override
	public Map<String, ? extends Point> getAllLocs() {
		return new ConcurrentHashMap<>(locs);
	}
	
}
